package com.xihuanjun.healthcode.entity.convert;

import com.xihuanjun.healthcode.entity.AllTypes;
import com.xihuanjun.healthcode.entity.ChangeRecord;
import com.xihuanjun.healthcode.entity.dto.ChangeRecordDTO;
import com.xihuanjun.healthcode.entity.vo.ChangeRecordVO;
import com.xihuanjun.healthcode.excel.ExcelRow;
import org.mapstruct.MapMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.stereotype.Repository;

import javax.xml.transform.Source;

/**
 * @author: 江溪浣
 * @createDate: 2022/10/25 14:11
 * @description:
 */
@Repository
@Mapper(componentModel = "spring",uses = {AllTypes.class},imports = {AllTypes.class})
public interface ChangeRecordConvert {

    ChangeRecord dto2record(ChangeRecordDTO dto);

    @Mapping(source = "createTime", target = "createTime", dateFormat = "yyyy-MM-dd HH:mm")
    @Mapping(source = "startTime", target = "startTime", dateFormat = "yyyy-MM-dd HH:mm")
    @Mapping(source = "endTime", target = "endTime", dateFormat = "yyyy-MM-dd HH:mm")
    @Mapping(target = "cardType",expression = "java(AllTypes.getCardTypeName(record.getCardType()))")
    @Mapping(target = "personType",expression = "java(AllTypes.getPersonTypeName(record.getPersonType(),record.getChangeType()))")
    @Mapping(target = "status",expression = "java(getStatusName(record.getStatus()))")
    @Mapping(target = "changeType",expression = "java(getChangeTypeName(record.getChangeType()))")
    ChangeRecordVO record2VO(ChangeRecord record);

    @Mapping(source = "startTime", target = "startTime", dateFormat = "yyyy/MM/dd")
    @Mapping(source = "endTime", target = "endTime", dateFormat = "yyyy/MM/dd")
    @Mapping(target = "cardType",expression = "java(AllTypes.getCardTypeId(row.getCardType()))")
    @Mapping(target = "personType",expression = "java(AllTypes.getPersonTypeId(row.getPersonType(),row.getChangeType()))")
    ChangeRecord excel2record(ExcelRow row);

    @Mapping(source = "startTime", target = "startTime", dateFormat = "yyyy/MM/dd")
    @Mapping(source = "endTime", target = "endTime", dateFormat = "yyyy/MM/dd")
    @Mapping(target = "cardType",expression = "java(AllTypes.getCardTypeId(row.getCardType()))")
    @Mapping(target = "personType",expression = "java(AllTypes.getPersonTypeId(row.getPersonType(),row.getChangeType()))")
    ChangeRecordDTO excel2DTO(ExcelRow row);


    ChangeRecordDTO record2DTO(ChangeRecord record);

    @Mapping(target = "cardType",expression = "java(AllTypes.getCardTypeName(dto.getCardType()))")
    @Mapping(target = "personType",expression = "java(AllTypes.getPersonTypeName(dto.getPersonType(),dto.getChangeType()))")
    ExcelRow dto2Excel(ChangeRecordDTO dto);


    default String getStatusName(int id){
        if(id==1){return "待处理";}
        if(id==2){return "已处理";}
        return null;
    }

    default  String getChangeTypeName(int id){
        if(id==1){return "赋红码";}
        if(id==2){return "赋橙码";}
        if(id==3){return "赋绿码";}
        return null;
    }
}
